
import * as XLSX from "xlsx";
interface IFileResult {
    columns: Array<string>
    data?: Array<Object>;
}
interface IFileReader extends FileReader {
    columns?: Array<string>
    data?: Array<Object>
}
export const getFileDate =(FILE:File):IFileReader => {
    let reader:IFileReader = new FileReader();
    reader.onload = (e:ProgressEvent<FileReader>):void => {
        // 获取文件内容
        let data:any = e.target?.result;
        // 改写文件
        let workbook:XLSX.WorkBook = XLSX.read(data, {type: 'binary'});
        // 获取表名
        const sheetName:string =workbook.SheetNames[0]
        // 获取表数据
        const sheetData:Array<Object> = XLSX.utils.sheet_to_json(workbook.Sheets[sheetName])
        // 设置表头
        reader.data = sheetData
        reader.columns = Object.keys(sheetData[0])
    };
    reader.readAsText(FILE,'utf-8')
    console.log(reader.result)
    return reader
}